﻿using CRM.Admin.Contracts.Contract.Customer;
using CRM.Admin.Contracts.Model.Customer;
using KingsSharp.Core;
using KingsSharp.Core.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CRM.Admin.Contracts.Dto.Customer;
using KingsSharp.Common.Data;
using KingsSharp.Common;

namespace CRM.Admin.Services.Service.Customer
{
    /// <summary>
    /// 简介
    /// </summary>
   public class CustomerProfilesService: ServiceBase,ICustomerProfilesService
    {
        private IRepository<CustomerProfiles,Guid> CustomerProfilesRepository;
        public CustomerProfilesService(IRepository<CustomerProfiles, Guid> _CustomerProfilesRepository)
            :base(_CustomerProfilesRepository.UnitOfWork)
        {
            CustomerProfilesRepository = _CustomerProfilesRepository;
        }

        public IQueryable<CustomerProfiles> Item
        {
            get
            {
                return CustomerProfilesRepository.Entities;
            }
        }

        public OperationResult Delete(params Guid[] ids)
        {
            ids.CheckNotNull("ids");
            var entity = CustomerProfilesRepository.Entities.Where(a => ids.Contains(a.Id)).ToList();
            entity.ForEach(a=>a.IsDeleted=true);
            int result = CustomerProfilesRepository.Update(entity.ToArray());
            return new KingsSharp.Common.Data.OperationResult(KingsSharp.Common.Data.OperationResultType.Success, "删除成功");
        }

        public OperationResult Insert(params CustomerProfilesDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            foreach (var t in dtos)
            {
                t.Id = Guid.NewGuid();
            }
            var result = CustomerProfilesRepository.Insert(dtos);
            return result;
        }

        public OperationResult Update(params CustomerProfilesDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            var result = CustomerProfilesRepository.Update(dtos);
            return result;
        }
    }
}
